package edu.bupt.c1array;

public class T21RotateArray {
    public void rotate(int[] nums, int k) {
        if(nums.length < 2)return;
        k = k%nums.length;
        k = nums.length - k;
        // 失误，这是向左移动了；
        reverse(nums,0,k);
        reverse(nums,k,nums.length);
        reverse(nums,0,nums.length);
    }

    private void reverse(int[] nums, int start, int end){
        int temp;
        for (int i=0;i<(end-start)/2;i++){
            temp = nums[start + i];
            nums[start + i] = nums[end -i -1];
            nums[end-1-i] = temp;
        }
    }
}
